Skip to content

Unified: Improve type inference for constructor calls - #22796

Draft
hvitved wants to merge 5 commits into
github:mainfrom
hvitved:unified/type-inference-constructors
Draft

hvitved wants to merge 5 commits into
github:mainfrom
hvitved:unified/type-inference-constructors

Conversation

@hvitved

@hvitved hvitved commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@hvitved
hvitved force-pushed the unified/type-inference-constructors branch 2 times, most recently from e5f4c43 to 909aa94 Compare October 10, 2026 07:22
@hvitved
hvitved force-pushed the unified/type-inference-constructors branch from 8102a8e to 80c4bfb Compare October 19, 2026 07:54
@hvitved
hvitved force-pushed the unified/type-inference-constructors branch from ecd7a28 to 843c4c4 Compare October 19, 2026 13:51
@hvitved
hvitved force-pushed the unified/type-inference-constructors branch from 843c4c4 to 4e6a1ef Compare October 19, 2026 14:16
@hvitved
hvitved force-pushed the unified/type-inference-constructors branch from 7a3d1be to 1c20541 Compare October 19, 2026 19:51
@hvitved
hvitved requested a max review from Copilot October 19, 2026 19:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Constructor inference loses contextual argument types and can produce incorrect inherited type mappings and superclass results.

4 open issues
What changed in this PR

Improves constructor-call type inference in Unified, particularly for inherited Swift initializers.

Changes:

  • Models constructors using receiver types.
  • Extends shared contextual inference support.
  • Adds inherited-constructor tests and updates expectations.
File Description
unified/​ql/​test/​library-tests/​type-inference/​type-inference.expected Updates generated inference expectations.
unified/​ql/​test/​library-tests/​type-inference/​lub.swift Updates an inline expected initializer target.
unified/​ql/​test/​library-tests/​type-inference/​constructors.swift Adds inherited and generic constructor cases.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeMention.qll Excludes enum cases from resolved types.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeInference.qll Adds receiver-based constructor inference.
unified/​ql/​lib/​codeql/​unified/​internal/​ExprPositions.qll Excludes enum cases from type contexts.
shared/​typeinference/​codeql/​typeinference/​internal/​TypeInference.qll Extracts reusable contextual typing logic and adds an inference hook.

Review effort: Max

Comment on lines +667 to +668
cd = i.getTargetImpl(_).asCallable() and
result = inferType(i.getArgument(0), path)
or
// inherited constructor
exists(TypeAbstraction abs, TypeMention constraint, TypeParameter tp |
BaseTypes::rootTypesSatisfaction(_, TClassLikeDeclarationType(declType), abs, _,
n =
any(TypeMention tm |
tm = getConstructionReceiver(_) and
result = tm.getTypeAt(path)
super.init() // $ target=C3.init
}

override convenience init() {

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants